class AtomicInteger {
    private int value;

    public int getAndIncrement() {
        int oldValue = value;
        while (CAS(value, oldValue, oldValue + 1) != true) {
            oldValue = value;
        }
        return oldValue;
    }

    private boolean CAS(int value, int oldValue, int i) {
        if (value == oldValue) {
            value = i;
            return true;
        }
        return false;
    }
}

